﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BOMS.DAL;
using System.Data;
namespace BOMS.WebUI
{
    public partial class sysWinceName : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                dbind();
            }
        }
        public void dbind()
        {
            DataTable dt = new DataTable();
            dt = SysAdmin.getWinceOfLan();
            this.GridView_Name.DataSource = dt;
            this.GridView_Name.DataBind();
        }

        protected void GridView_User_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int rowIndex = Convert.ToInt32(e.CommandArgument);
            if (rowIndex > -1)
            {
                string id = this.GridView_Name.DataKeys[rowIndex].Value.ToString();
               if (e.CommandName == "delUser")
                {
                    Boolean IsSuccess = SysAdmin.deleteWince(id);
                    Type cstype = this.GetType();
                    if (IsSuccess == true)
                    {
                        ClientScript.RegisterStartupScript(cstype, "key", "<script>window.alert('删除成功！');window.location.href=window.location.href;</script>");
                    }
                    else
                    {
                        ClientScript.RegisterStartupScript(cstype, "key", "<script>window.alert('删除失败！');</script>");
                    }

                }
                

            }
        }

        protected void GridView_User_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)//判断是不是数据行
            {
                //当鼠标停留时更改背景色
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#abcdef'");
                //当鼠标移开时还原背景色
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
                if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
                {
                    Button btdel = e.Row.Cells[5].Controls[0] as Button;
                    btdel.Attributes.Add("onclick", "javascript:if( confirm('确定删除该主机?')){}else{return false;}");
                }
            }
        }

        protected void GridView_Name_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView_Name.EditIndex = e.NewEditIndex;
            dbind();

        }

        protected void GridView_Name_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            string id = GridView_Name.DataKeys[e.RowIndex].Value.ToString();
            string name = ((TextBox)(GridView_Name.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
            SysAdmin.updateWinceName(id,name);
            GridView_Name.EditIndex = -1;
            dbind();

        }

        protected void GridView_Name_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            GridView_Name.EditIndex = -1;
            dbind();
        }

    }
}